package com.bloveoacom.observer;

import com.bloveoacom.exception.ApiException;
import com.bloveoacom.mvp.IView;

import io.reactivex.subscribers.DisposableSubscriber;

/**
 * author: yjl
 * e-mail: 1271901673@qq.com
 * time  : 2018/9/11
 * desc  :
 */
public class BaseSubscriber2<T> extends DisposableSubscriber<T> {
    private IView mIView;

    public BaseSubscriber2() {
    }
    public BaseSubscriber2(IView mIView) {
        this.mIView = mIView;
    }

    @Override
    public void onNext(T o) {

    }

    @Override
    public void onError(Throwable t) {
        if(mIView !=null){
            if(t instanceof ApiException){
                mIView.showErrorException(((ApiException) t));
            }else{
                mIView.showErrorException(ApiException.handleException(t));
            }
            mIView.hideLoadingDialog();
            mIView.finishRefresh();
        }
    }

    @Override
    public void onComplete() {
        if(mIView !=null){
            mIView.hideLoadingDialog();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if(mIView !=null){
            mIView.showLoadingDialog("加载中...");
        }
    }
}
